<h1 id="内置函数">内置函数</h1>
<p><code>Quick</code>的标准库通过内置函数提供，它本身毫无扩展性可言。<br>但你要做的事在它的服务范围内，它可能是个很好的选择。</p>
<h3 id="命令行相关">命令行相关</h3>
<p>使用这些命令使得我们可以用<code>Quick</code>替代 Shell脚本， windows的批处理脚本(<code>cmd</code>)</p>
<table>
<thead>
<tr>
<th>函数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>cmd</td>
<td>命令行调用 (windows下用的<code>cmd.exe</code>, 每次只能执行单个命令； linux下用的<code>bash</code>, 一次可执行多个命令)</td>
</tr>
<tr>
<td>setpwd</td>
<td>别名：<code>cd</code>,  设置工作路径（命令行的当前路径）</td>
</tr>
</tbody></table>
<h3 id="系统相关">系统相关</h3>
<table>
<thead>
<tr>
<th>函数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>sys</td>
<td>获取当前系统名称</td>
</tr>
<tr>
<td>cpuNum</td>
<td>获取cpu的逻辑核数</td>
</tr>
<tr>
<td>envs</td>
<td>获取所有环境变量</td>
</tr>
<tr>
<td>env</td>
<td>获取单个环境变量</td>
</tr>
<tr>
<td>setenv</td>
<td>设置环境变量(仅对当前脚本有效)</td>
</tr>
<tr>
<td>home</td>
<td>获取并打印环境变量QK_HOME</td>
</tr>
<tr>
<td>cost</td>
<td>统计脚本耗时</td>
</tr>
<tr>
<td>openBrowser(url)</td>
<td>别名<code>ob</code>, 在浏览器中打开指定url</td>
</tr>
</tbody></table>
<h2 id="数学函数">数学函数</h2>
<table>
<thead>
<tr>
<th>函数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>abs(number)</td>
<td>取绝对值</td>
</tr>
<tr>
<td>pow(number, int)</td>
<td>次方计算</td>
</tr>
<tr>
<td>sqrt(number)</td>
<td>平方根计算</td>
</tr>
<tr>
<td>round(float)</td>
<td>四舍五入取整</td>
</tr>
<tr>
<td>fix(float, int)</td>
<td>精确小数位</td>
</tr>
</tbody></table>
<p>实例</p>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-title function_">abs</span>(-<span class="hljs-number">3.15</span>)) <span class="hljs-comment">// 3.15</span>
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">pow</span>(<span class="hljs-number">4</span>, <span class="hljs-number">3</span>)) <span class="hljs-comment">// 64</span>
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">sqrt</span>(<span class="hljs-number">81</span>)) <span class="hljs-comment">// 9</span>
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">round</span>(<span class="hljs-number">3.14</span>)) <span class="hljs-comment">// 3</span>
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">round</span>(<span class="hljs-number">6.5</span>)) <span class="hljs-comment">// 7</span>
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">fix</span>(<span class="hljs-number">3.8213</span>, <span class="hljs-number">2</span>)) <span class="hljs-comment">// 3.82</span>
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">fix</span>(<span class="hljs-number">2.5591</span>, <span class="hljs-number">2</span>)) <span class="hljs-comment">// 2.56</span>
</code></pre>
<h2 id="随机数">随机数</h2>
<table>
<thead>
<tr>
<th>函数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>random(n)</td>
<td>产生[0, n)的非负随机数</td>
</tr>
<tr>
<td>random(n, m)</td>
<td>产生[n, m)的非负随机数</td>
</tr>
</tbody></table>
<pre><code class="hljs language-javascript"><span class="hljs-keyword">for</span> i = <span class="hljs-number">0</span>; i&lt;<span class="hljs-number">20</span>; i++ {
    <span class="hljs-title function_">println</span>(i, <span class="hljs-string">&quot;-&gt;&quot;</span>, <span class="hljs-title function_">random</span>(<span class="hljs-number">10</span>))
}

<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;----------------------&quot;</span>)
<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;######################&quot;</span>)
<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;----------------------&quot;</span>)

<span class="hljs-keyword">for</span> i = <span class="hljs-number">0</span>; i&lt;<span class="hljs-number">20</span>; i++ {
    <span class="hljs-title function_">println</span>(i, <span class="hljs-string">&quot;-&gt;&quot;</span>, <span class="hljs-title function_">randomRange</span>(<span class="hljs-number">10</span>, <span class="hljs-number">15</span>))
}
</code></pre>
<h3 id="常用函数">常用函数</h3>
<table>
<thead>
<tr>
<th>函数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>sleep(ms)</td>
<td>使当前协程进入休眠状态，单位为ms</td>
</tr>
<tr>
<td>uuid()</td>
<td>返回32个随机字符[0-9a-z]组成的字符串</td>
</tr>
<tr>
<td>uuidRaw()</td>
<td>带&#39;-&#39;的uuid</td>
</tr>
<tr>
<td>key16()</td>
<td>生成16字节长度的随机key,以base64形式返回</td>
</tr>
<tr>
<td>key24()</td>
<td>生成24字节长度的随机key,以base64形式返回</td>
</tr>
<tr>
<td>key32()</td>
<td>生成32字节长度的随机key,以base64形式返回</td>
</tr>
</tbody></table>
<h3 id="编码相关">编码相关</h3>
<table>
<thead>
<tr>
<th>函数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>base64Encode</td>
<td>别名<code>base64</code>, base64编码</td>
</tr>
<tr>
<td>base64Decode</td>
<td>别名<code>debase64</code>, base64解码</td>
</tr>
<tr>
<td>gzipEncode</td>
<td>别名<code>gzip</code>, gzip编码</td>
</tr>
<tr>
<td>gzipDecode</td>
<td>别名<code>degzip</code>, gzip解码</td>
</tr>
<tr>
<td>md5</td>
<td>md5编码</td>
</tr>
<tr>
<td>aesEncrypt(data, key)</td>
<td>别名<code>aes</code>, AES对称加密</td>
</tr>
<tr>
<td>aesDecrypt(data, key)</td>
<td>别名<code>deaes</code>, AES对称解密</td>
</tr>
</tbody></table>
<pre><code class="hljs language-javascript">tmp = <span class="hljs-title function_">gzip</span>(<span class="hljs-string">&quot;中华人民共和国&quot;</span>)
<span class="hljs-title function_">println</span>(tmp)
<span class="hljs-title function_">printf</span>(<span class="hljs-string">&quot;%X\n&quot;</span>, tmp)
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">degzip</span>(tmp))
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">base64</span>(tmp))
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">degzip</span>(tmp).<span class="hljs-title function_">str</span>())

<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;-----------------------&quot;</span>)
tmp = <span class="hljs-title function_">base64</span>(<span class="hljs-string">&quot;一念花开，君临天下&quot;</span>)
<span class="hljs-title function_">println</span>(tmp)
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">debase64</span>(tmp))
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">debase64</span>(tmp).<span class="hljs-title function_">str</span>())

<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;-----------------------&quot;</span>)
tmp = <span class="hljs-title function_">md5</span>(<span class="hljs-string">&quot;一念天堂，一念地狱。上穷碧落下黄泉，我主沉浮。&quot;</span>)
<span class="hljs-title function_">println</span>(tmp)
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">md5</span>(<span class="hljs-number">123456</span>))

<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;AES-----------------------&quot;</span>)
k = <span class="hljs-title function_">key32</span>()
data = <span class="hljs-string">&quot;繁星璀璨，独赏明月&quot;</span>
tmp = <span class="hljs-title function_">aes</span>(data, k)
<span class="hljs-title function_">println</span>(k)
<span class="hljs-title function_">println</span>(tmp)
<span class="hljs-title function_">println</span>(<span class="hljs-title function_">deaes</span>(tmp, k))
</code></pre>
